package one.linkList;

/**
 * 环形链表I
 * 给定一个链表，判断链表中是否有环。
 */
public class HasCycle {
    //时间复杂度：O(n)
    //快慢指针
    public boolean hasCycle(ListNode head) {
        ListNode fast = head;
        ListNode slow = head;
        while(fast != null && fast.next != null){
            fast = fast.next.next;
            slow = slow.next;
            if(fast == slow){
                return true;
            }
        }
        return false;
    }
}
